#include <ansi_c.h>
#define SIZE 6
#define nr 'n'
#define bl 'b'
#define ab ' '
#define x  'x'
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*PROTOTYPE DE LA FONCTION PRINCIPALE*/
void detection(char tab[SIZE][SIZE]);
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*PROTOTYPE DES FONCTIONS CASES X*/ 
char case_haut_gauche(char,char,char);
char case_haut_centre(char,char,char);   
char case_haut_droite(char,char,char);   
char case_milieu_gauche(char,char,char);   
char case_milieu_droite(char,char,char);   
char case_bas_gauche(char,char,char);   
char case_bas_cantre(char,char,char);   
char case_bas_droite(char,char,char);
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*PROTOTYPE DE LA FONCTION VERIFICATION*/
char verification(char,char,char);
/*char verification_2(char,char,char);*/    
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*VARIABLE GENERALE*/
char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,nr,nr,bl,ab,ab}, 				/*definition du plateau*/ 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
 					  };
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION MAIN*/
void main(void)
{
 int i;
 int j;
 int b=0;
 int n=0;

 for(i=0;i<SIZE;i++)				 /*placement des lignes et colonnes*/
 {									 /*premier temps \n caractere de retour a la ligne, pour chaque ligne*/
  printf("\n");
  for(j=0;j<SIZE;j++)				 /*ecriture de la ligne caractere par caractere*/
  {
   printf("\t%c",tab[i][j]);
   if(tab[i][j]==bl)
	   b=b+1;
   else if (tab[i][j]==nr)
	   n=n+1;
  }
 printf("\n\n");
 }
 printf("\n\n");
 printf("\npoint blanc :%d\t\tpoint noir :%d",b,n);
 detection(tab);
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION PRINCIPALE*/
void detection(char tab[SIZE][SIZE])
{
 int i;
 int j;
 int b=0;
 int n=0;
 int k=0;
 for(i=0 ; i<SIZE ; i++)
 {
  for(j=0 ; j<SIZE ; j++)
  {
   if(tab[i][j]==nr)
   {
	tab[i-1][j-1]=case_haut_gauche(tab[i-1][j-1],tab[i][j],tab[i+1][j+1]);
	tab[i-1][j]=case_haut_centre(tab[i-1][j],tab[i][j],tab[i+1][j]);   
	tab[i-1][j+1]=case_haut_droite(tab[i-1][j+1],tab[i][j],tab[i+1][j-1]);   	  /*declaration des differents situations des pions*/
	tab[i][j-1]=case_milieu_gauche(tab[i][j-1],tab[i][j],tab[i][j+1]);   
	tab[i][j+1]=case_milieu_droite(tab[i][j+1],tab[i][j],tab[i][j-1]);   
	tab[i+1][j-1]=case_bas_gauche(tab[i+1][j-1],tab[i][j],tab[i-1][j+1]);   
	tab[i+1][j]=case_bas_cantre(tab[i+1][j],tab[i][j],tab[i-1][j]);   
	tab[i+1][j+1]=case_bas_droite(tab[i+1][j+1],tab[i][j],tab[i-1][j-1]);   
   }
  }
 }
/*------------------------------------------------------------------------------------------------------------------------------------------*/
 														/*AFFICHE DE NOUVEAUX LE TABLEAUX*/
 for(i=0;i<SIZE;i++)				 /*placement des lignes et colonnes*/
 {									 /*premier temps \n caractere de retour a la ligne, pour chaque ligne*/
  printf("\n");
  for(j=0;j<SIZE;j++)				 /*ecriture de la ligne caractere par caractere*/
  {
   printf("\t%c",tab[i][j]);
   if(tab[i][j]==bl)
	   b=b+1;
   else if (tab[i][j]==nr)
	   n=n+1;
  }
 printf("\n\n");
 }
 printf("\n\n");
 printf("\npoint blanc :%d\t\tpoint noir :%d",b,n);
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_haut_gauche(char caract,char case_nr,char case_bl)
{
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
  /*if(case_bl==bl)
  { */
   caract=verification(caract,case_nr,case_bl);
  /*}*/
  /*else
  {
   caract=verification_2(caract,case_nr,case_bl);
  }*/  
 }   
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_haut_centre(char caract,char case_nr,char case_bl)
{
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
  /*if(case_bl==bl)
  { */
   caract=verification(caract,case_nr,case_bl);
  /*}*/
  /*else
  {
   caract=verification_2(caract,case_nr,case_bl);
  }*/  
 }   
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_haut_droite(char caract,char case_nr,char case_bl)
{
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
  /*if(case_bl==bl)
  { */
   caract=verification(caract,case_nr,case_bl);
  /*}*/
  /*else
  {
   caract=verification_2(caract,case_nr,case_bl);
  }*/  
 }   
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_milieu_gauche(char caract,char case_nr,char case_bl)
{
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
  /*if(case_bl==bl)
  { */
   caract=verification(caract,case_nr,case_bl);
  /*}*/
  /*else
  {
   caract=verification_2(caract,case_nr,case_bl);
  }*/  
 }   
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_milieu_droite(char caract,char case_nr,char case_bl)
{
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
  /*if(case_bl==bl)
  { */
   caract=verification(caract,case_nr,case_bl);
  /*}*/
  /*else
  {
   caract=verification_2(caract,case_nr,case_bl);
  }*/  
 }
  return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_bas_gauche(char caract,char case_nr,char case_bl)
{
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
  /*if(case_bl==bl)
  { */
   caract=verification(caract,case_nr,case_bl);
  /*}*/
  /*else
  {
   caract=verification_2(caract,case_nr,case_bl);
  }*/
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_bas_cantre(char caract,char case_nr,char case_bl)
{
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
  /*if(case_bl==bl)
  { */
   caract=verification(caract,case_nr,case_bl);
  /*}*/
  /*else
  {
   caract=verification_2(caract,case_nr,case_bl);
  }*/  
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_bas_droite(char caract,char case_nr,char case_bl)
{
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
  /*if(case_bl==bl)
  { */
   caract=verification(caract,case_nr,case_bl);
  /*}*/
  /*else
  {
   caract=verification_2(caract,case_nr,case_bl);
  } */ 
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
															/*FONCTION VERIFICATION*/
char verification(char case_x,char case_nr, char case_bl)
{
 if(case_nr==nr && case_x==x && case_bl==bl)
 {
 }
 else
 {
  case_x = ab;
 }
 return case_x ;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
/*char verification_2(char case_x,char case_nr,char case_bl)
{
 int i;
 int j;
 for(i=0 ; i<SIZE ; i++)
 {
  for(j=0 ; j<SIZE ; j++)
  {
   if((j<SIZE-1 && tab[i][j]==nr && tab[i][j+1]==nr && tab[i][j+2]==bl) || (j<SIZE-1 && tab[i][j]==bl && tab[i][j+1]==nr && tab[i][j+2]==bl))
   {
    case_x=x;
	return case_x;
   }
   else if((i<SIZE-1 && tab[i][j]==nr && tab[i+1][j] && tab[i+2][j]) || (i<SIZE-1 && tab[i][j]==bl && tab[i+1][j]==nr && tab[i+2][j]==nr))
   {
    case_x=x;  
	return case_x;
   }
   else if((i<SIZE-1 && i>0 && j<SIZE-1 && j>0 && tab[i+1][j+1]==nr && tab[i][j]==nr && tab[i-1][j-1]==bl) || (i<SIZE-1 && i>0 && j<SIZE-1 && j>0 && tab[i+1][j+1]==bl && tab[i][j]==nr && tab[i-1][j-1]==nr))
   {
     case_x=x;  
	 return case_x;
   }
   else if((i<SIZE-1 && i>0 && j<SIZE-1 && j>0 && tab[i+1][j-1]==nr && tab[i][j]==nr && tab[i-1][j+1]==bl) || (i<SIZE-1 && i>0 && j<SIZE-1 && j>0 && tab[i+1][j-1]==bl && tab[i][j]==nr && tab[i-1][j+1]==nr))
   {
    case_x=x;  
	return case_x;
   }
   else 
   {
    case_x= ab;
   }
   return case_x;
  }
 }
} */
